
<template>
  <div>
    <div id="main" style="width: 500px; height: 500px;" ref="main">
    </div>
  </div>
</template>

<script>
  import axios from 'axios'
  import Qs from 'qs'

  export default {
    name: 'chart2',
    data() {
      return {
        statistics: []
      }
    },
    mounted() {
      this.drawLine();
    },
    methods: {
      drawLine() {
        // 基于准备好的dom，初始化echarts实例
        var mythis = this;
        axios({
          method: 'get',
          url: 'http://localhost:8080/employee/countEdu',
        }).then(function(rs) {
          // mythis.statistics=rs.data;
          let myChart = mythis.$echarts.init(mythis.$refs.main);
          // 绘制图表
          myChart.setOption({
            title: {
              text: '员工学历',
              left: 'center',
            },
            tooltip: {
              trigger: 'item',
              formatter: '{b}:{c}: ({d}%)',
            },
            legend: {
              orient: 'vertical',
              left: 'left'
            },
            series: [{
              name: '学历',
              type: 'pie',
              radius: '50%',
              data: mythis.initData(rs.data, 'name', 'value'),
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }]
          });
        })
      },

      initData(data, name, value) {
        let seriesData = [];

        // console.log(data)
        data.forEach(item => {
          let outObj = {};
          outObj.name = item.name;
          outObj.value = item.value;
          seriesData.push(outObj);
        });
        this.statistics = seriesData;
        return seriesData;
      }
    }
  }
</script>

<style>
</style>
